FROM node:latest
LABEL maintainer="jianglinjie@163.com"

RUN echo "begin build local image"

# 环境变量
ENV APP_DIR /home/app
ENV LOG_DIR /home/log
ENV TMP_UPLOAD_FILE_DIR /home/tmp
ENV UPLOAD_FILE_DIR /home/files
# ENV KEYMETRICS_PUBLIC=a1de2hhy7o8kukw
# ENV KEYMETRICS_SECRET=5mda6k1rc950ryz

# 创建目录
RUN mkdir -p ${APP_DIR}
RUN mkdir -p ${LOG_DIR}
RUN mkdir -p ${TMP_UPLOAD_FILE_DIR}
RUN mkdir -p ${UPLOAD_FILE_DIR}

# 设置工作空间
WORKDIR ${APP_DIR}
COPY package-lock.json .
COPY package.json .

## install dependency
RUN npm config set registry https://registry.npm.taobao.org
RUN npm install
RUN npm install pm2 -g

# 拷贝当前目录到镜像
COPY bin bin/
COPY src src/
COPY deploy/local/config config/
COPY ecosystem.config.js .
COPY .babelrc .

#编译原码
RUN npm run build

## 声明VOLUME，运行时可以绑定
VOLUME ${LOG_DIR} ${TMP_UPLOAD_FILE_DIR} ${UPLOAD_FILE_DIR}

EXPOSE 3001

RUN ls -al
RUN cat config/config.js

CMD ["pm2-docker", "start", "ecosystem.config.js"]
